package com.marketingexpert.controller.statemgnt;

import java.io.PrintWriter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONArray;

import org.apache.log4j.Logger;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;

import com.marketingexpert.exception.MarketingExpertException;
import com.marketingexpert.service.statreport.StatReportService;

public class QueryActivityVisitCountsController implements Controller {

	private static Logger logger = Logger.getLogger(QueryActivityVisitCountsController.class);
	
	private StatReportService  statReportService;
	
	@Override
	public ModelAndView handleRequest(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		
		response.setContentType("application/x-json;charset=GBK"); 
		response.setHeader("Pragma", "No-cache"); 
		response.setHeader("Cache-Control", "no-cache"); 
		response.setHeader("Cache-Control", "no-store"); 
		response.setDateHeader("Expires", 0);  
		PrintWriter out = response.getWriter(); 
		
		String activityes = request.getParameter("activityes[]");
		
		String[] activityesArray = activityes.split(",");
		try {
		JSONArray jsonArray = statReportService.queryActivityVisitCounts(activityesArray);
		out.print(jsonArray);
		return null;
		} catch(MarketingExpertException e) {
			logger.error("QueryActivityVisitCountsController.line42 query activityVisitRecord Error.", e);
			throw e;
		}
	}

	public StatReportService getStatReportService() {
		return statReportService;
	}

	public void setStatReportService(StatReportService statReportService) {
		this.statReportService = statReportService;
	}
}
